package com.zhiyou100.controller.user;

import com.zhiyou100.dao.Impl.UserDaoImpl;
import com.zhiyou100.emtity.PageModel;
import com.zhiyou100.emtity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @description:
 * @author: 马跃
 * @create: 2021-01-20 10:21
 **/
@WebServlet("/userQueryAll")
public class UserQueryAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String currentPage = request.getParameter("currentPage");
        int currNum = currentPage == null ? 1 : Integer.parseInt("currentPage");
        UserDaoImpl dao = new UserDaoImpl();
        List<User> list = dao.findAllUser(currNum);
        int count = dao.findAllUserCount();
        PageModel<User> page = new PageModel<User>(currNum, (count + 4 ) / 5, 11, list);
        request.getSession().setAttribute("pageModel", page);
        request.getRequestDispatcher("./Adminastrator/user/userManager.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
